package com.zsrt.common.dd.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.zsrt.common.dd.dao.DataDirectoryDao;
import com.zsrt.common.entity.Combobox;
import com.zsrt.utils.DBUtil;

public class DataDirectoryDaoImpl implements DataDirectoryDao {

	@Override
	public List<Combobox> findChildrenByParentId(int parentId) throws SQLException {
		List<Combobox>  list = new ArrayList<Combobox>();
		String sql = "select id as valueField, children_name as textField from dd_detail_t where parent_id=?";
		Connection connection = DBUtil.getConnection();
		PreparedStatement ps = connection.prepareStatement(sql);
		
		ps.setInt(1, parentId);
		
		ResultSet rs = ps.executeQuery();
		
		while(rs.next()) {
			Combobox combobox= new Combobox();
			combobox.setValueField(rs.getString("valueField"));
			combobox.setTextField(rs.getString("textField"));
			list.add(combobox);
			
		}
		DBUtil.closeResources(rs, ps, connection);
		return list;
	}

}
